<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="/socket.io/socket.io.js"></script>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>

<p>hello world</p>
    <h3></h3>
    <form action="" onsubmit="sendMessage(); return false;">
    <input id="message" type="text">
    <input type="submit" value="发送">
</form>
    <script>
    $('.aa').click(function(){
        $(this).hide()
    })
        socket = io.connect('127.0.0.1:3000');
        socket.emit("message", {"name" : navigator.userAgent, "msg" : "hello world"});
        socket.on("message", function(obj) {
            console.log(obj);

        });
        socket.on("eventC", function(obj) {
            console.log(obj);
            console.log("当前客户端的id："+obj.id)//当人数增多时，id就往后移，显然不是我们想要的
            console.log("当前在线总人数为："+obj.users.length)
            $('h3').html("当前在线总人数为"+obj.users.length)
            for (var i = 0; i < obj.users.length; i++) {
                
                console.log("他们分别是："+obj.users[i])

            }
       
        });
         socket.on("message", function(obj) {
            console.log("服务器广播消息是",obj);
        })
         socket.on("leave", function(obj) {
            console.log("服务器广播消息是",obj);
        })
         socket.on("eventB", function(obj) {
            console.log(obj);
        
        });
         function sendMessage(){
               socket.emit('eventB',{msg:$("#message").val()})
         }
            
       
    </script>
    
</body>
</html>